package org.mc.service;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mc.common.data.ResultData;
import org.mc.common.handler.annotation.LockDist;
import org.mc.domainservice.AccountDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by luoxf on 2018/9/13.
 */
@RestController
@Api(value = "AccountRestServiceV1", tags = "AccountRestServiceV1", description = "账户")
public class AccountRestServiceV1 {

    @Autowired
    private AccountDomainService accountDomainService;

    @RequestMapping(value = "/v1/account", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "账户", notes = "账户", httpMethod = "POST", tags = "AccountRestServiceV1")
    public ResultData account() {

        for (int i = 1; i <= 1; i++) {
            accountDomainService.aa();
            //accountDomainService.bb();
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    add();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    sub();
                }
            }
        }).start();

        return ResultData.ok();
    }

    @LockDist(value = "account")
    public void add() {
        accountDomainService.addAccount();
    }

    @LockDist(value = "account")
    public void sub() {
        accountDomainService.subAccount();
    }

}
